// pages/moments/comment/comment.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    releaseFocus: false,
    momentsMsgComment: null,
    momentsMsg: null,
    user: null,
    commentList: [],
    momentid: 0,
    commtext: ""     //评论内容
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var mid = options.id;
    console.log("跳转来的Url：" + mid);
    if (mid) {
      this.setData({
        momentid: mid
      });
    }
  },
  //发送评论
  sendMsg: function (e) {
    var that = this;
    if (!this.data.commtext) {
      wx.showModal({
        content: '请输入内容',
        showCancel: false
      })
      return false;
    }

    wx.request({
      url: getApp().globalData.urlPath + '/api/Moments/AddComment',
      method: 'POST',
      data: {
        Token: app.globalData.loginInfo.Token,
        FromOpenid: getApp().globalData.openid,
        TopicId: that.data.momentsMsg.ID,
        ContentMsg: that.data.commtext,
      },
      success: function (res) {
        app.globalData.loginInfo.Token = res.data.TokenUpdate;
        console.log("评论完成返回：" + res.data);
        that.getMomentsMsgComment();
        that.setData({
          commtext: ""
        });
        // wx.switchTab({
        //   url: '/pages/moments/moments'
        // })
      }
    });
  },
  bindTextAreaBlur: function (e) {
    this.setData({
      commtext: e.detail.value
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getMomentsMsgComment();
  },
  getMomentsMsgComment: function (){
    //获取圈子信息，包含评论
    var that = this;
    wx.request({
      url: getApp().globalData.urlPath + '/api/Moments/GetMomentsMsgComment',
      data: {
        Token: app.globalData.loginInfo.Token,
        id: that.data.momentid
        //id: 30
      },
      success: function (res) {
        app.globalData.loginInfo.Token = res.data.TokenUpdate;
        console.log("获取评论成功 " + JSON.stringify(res.data));
        if (res.data == null) return;
        that.setData({
          momentsMsgComment: res.data,
          momentsMsg: res.data.MomentsMsg,
          commentList: res.data.CommentList,
          user: res.data.User
        });
      }
    }); 
  },
  goquanzi: function () {
    wx.switchTab({
      url: '../moments',
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})